package com.lhh.springcloud.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 李洪豪
 * @Sno 20220301044
 */
@RestController
@Slf4j
@RefreshScope //数springcloud的原生注解，用于动态获取配置中心配置，即当我们无需重新启动注册到nacos的微服务就可获取到更新的配置
public class NacosConfigController {
    //获取配置中心的信息
    //注意：${config.ip}并不是随便写的，要根据配置中心的配置进行引用赋值
    @Value("${config.ip}")
    private String configIp;
    @Value("${config.name}")
    private String configName;

    @GetMapping(value = "/nacos/config/ip")
    public String getConfigIp(){
        return configIp;
    }

    @GetMapping(value = "/nacos/config/name")
    public String getConfigName(){
        return configName;
    }
}
